const app = getApp()
const { Api } = app.globalData

Page({
	data: {
      position: app.globalData.config.schoolPosition,
		banners: [],
		about: {} // 学校简介
	},

	onLoad() {
		// app.getUserInfo().then(user => {
		// 	app.post(Api.user.update, {
		// 		nickname: user.nickName,
		// 		avatar: user.avatarUrl,
		// 	}).then(res => {
				
		// 	})
      // })
		this.getBanners()
		this.getArticle()
      	this.getArticles()
	},

	getBanners() {
		app.get(Api.banner).then(res => {
			res.code === 1 && this.setData({
				banners: res.data
			})
		})
   },

	// 学校简介
	getArticle() {
		app.get(Api.article.item, {
			id: 'a598adc0-e91b-45c5-a097-f75d85bc5e0d',
		}).then(res => {
			res.code === 1 && this.setData({
				about: res.data
			})
		})
	},

   // 获取校园一角 文章分类 => 3
   getArticles() {
      app.get(Api.article.list, {
			class_id: 1,
			page: 1,
			limit: 4
		}).then(res => {
			const {data} = res;
			// console.log(data);
			res.code === 1 && this.setData({
				articles: data.articles
			})
      })
   },
   
   // 点击校园导航打开地图
   openLocation(e) {
      wx.openLocation({
         ...this.data.position,
         name: '河南理工大学',
      })
   }
})